/*
* Copyright (c)  2017, ueboot.com
* All rights reserved.
* 2017-10-12 14:37:57
*/
package com.ueboot.weishop.service.setting.impl;

import com.ueboot.core.repository.BaseRepository;
import com.ueboot.core.service.impl.BaseServiceImpl;
import com.ueboot.weishop.entity.setting.SpecOptionValueEntity;
import com.ueboot.weishop.entity.setting.SpecificationEntity;
import com.ueboot.weishop.repository.setting.SpecOptionValueRepository;
import com.ueboot.weishop.service.setting.SpecOptionValueService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by yangkui  on 2017-10-12 14:37:57.
 *
 * @since 2.0 by autocode
 */
@Slf4j
@Service
public class SpecOptionValueServiceImpl extends BaseServiceImpl<SpecOptionValueEntity> implements SpecOptionValueService{
    @Autowired
    private SpecOptionValueRepository specOptionValueRepository;

    @Override
    protected BaseRepository getBaseRepository() {
         return specOptionValueRepository;
    }

    @Override
    public Page<SpecOptionValueEntity> findBySpecId(Pageable pageable, Long specId) {
        SpecOptionValueEntity entity = new SpecOptionValueEntity();
        SpecificationEntity spec = new SpecificationEntity();
        spec.setId(specId);
        entity.setSpec(spec);
        ExampleMatcher matcher = ExampleMatcher.matching().withIgnoreNullValues()
                .withMatcher("spec.id",matcher1 -> matcher1.exact());
        return specOptionValueRepository.findAll(Example.of(entity,matcher),pageable);
    }

    @Override
    public List<SpecOptionValueEntity> findBySpecId(Long categoryId) {
        return specOptionValueRepository.findBySpecId(categoryId);
    }
}
